<!--
 * @Description: 发布公告
 * @Author: zhangweigang
 * @Date: 2021-03-23 23:02:56
 * @LastEditTime: 2021-04-24 13:46:58
 * @LastEditors: zhangweigang
-->
<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }"><span class="tW">首页</span></el-breadcrumb-item>
      <el-breadcrumb-item><span class="tW">公告管理</span></el-breadcrumb-item>
      <el-breadcrumb-item><span class="tW">发布公告</span></el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card class="box-card">
      <!-- 表单区域 -->
      <el-form :model="noticeRuleForm" :rules="noticeRules" ref="noticeForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="公告标题" prop="noticeTitle">
          <el-input v-model="noticeRuleForm.noticeTitle" placeholder="请输入公告标题"></el-input>
        </el-form-item>
        <el-form-item label="公告内容" prop="noticeContent">
          <el-input type="textarea" v-model="noticeRuleForm.noticeContent" :autosize="{ minRows: 5, maxRows: 10 }" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="备注信息" prop="remark">
          <el-input v-model="noticeRuleForm.remark" placeholder="请输入备注信息"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('noticeForm')">提交</el-button>
          <el-button @click="resetForm('noticeForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import bookShareManagerInfoAipService from '@/network/aipBookShareService.js'
export default {
  data() {
    return {
      // 其他附加参数
      otherInfo: {
        noticeType: 2, // 公告类型（1通知 2公告）
        status: 0, // 公告状态（0正常 1关闭）
        delFlag: 1 // 1:未删除 2:已删除
        // creator: localStorage.getItem('adminname')
      },
      // 公告信息表单
      noticeRuleForm: {
        noticeTitle: '',
        noticeContent: '',
        remark: ''
      },
      noticeRules: {
        noticeTitle: [{ required: true, message: '请输入公告名称', trigger: 'blur' }],
        noticeContent: [{ required: true, message: '请输入公告内容', trigger: 'blur' }],
        remark: [{ required: true, message: '请输入备注信息', trigger: 'change' }]
      }
    }
  },
  methods: {
    // 提价公告信息
    submitForm(formName) {
      let params = {
        ...this.otherInfo,
        ...this.noticeRuleForm
      }
      this.$refs[formName].validate(valid => {
        if (valid) {
          bookShareManagerInfoAipService.declareNewNotice(params).then(res => {
            this.$message({
              showClose: true,
              message: '恭喜您，公告发布成功！',
              type: 'success',
              duration: 4000
            })
            this.noticeRuleForm = {}
          })
        } else {
          this.$message({
            showClose: true,
            message: '校验失败，请重新输入！',
            type: 'warning',
            duration: 4000
          })
          return
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="less" scoped></style>
